package com.cgsd.heyu.widgets.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.library.utils.BeanUtils;
import com.cgsd.heyu.R;
import com.cgsd.heyu.adapter.PermissionAdapter;
import com.cgsd.heyu.entity.TabEntity;

import java.util.List;


/**
 * @author xiaoxing
 *  下载任务弹窗
 */

public class PermissionDialog extends BaseDialog<List<TabEntity>>{
    private OnDialogListener onDialogListener;
    private PermissionAdapter adapter;

    public void setOnDialogListener(OnDialogListener onDialogListener) {
        this.onDialogListener = onDialogListener;
    }

    public PermissionDialog(@NonNull Context context, List<TabEntity> data) {
        super(context,data);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_premission;
    }

    @Override
    protected void initView() {
        if (BeanUtils.isEmpty(data)){
            return;
        }
        RecyclerView mRecyclerView = findViewById(R.id.mRecyclerView);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new PermissionAdapter(mContext,data);
        mRecyclerView.setAdapter(adapter);


        findViewById(R.id.tv_got_it).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDialogListener != null){
                    onDialogListener.confirm();
                }
            }
        });
    }


    /**
     * 设置数据
     */
    public void setData(List<TabEntity> data) {
        if (data == null){
            return;
        }
        this.data.addAll(data);
        adapter.notifyDataSetChanged();
    }

    public interface OnDialogListener{
        /**
         * 确认
         */
        void confirm();
    }

}
